<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="common/head::head"></th:block>
    <style>
        .clear {
            margin-left: 20px;
        }
    </style>
</head>

<body>

<th:block th:unless="${node}">
    <blockquote class="layui-elem-quote">服务端文件缓存：[[${cacheFileSize}]]
        <button type="button" class="layui-btn layui-btn-sm clear" t="serviceCacheFileSize">清空</button>
    </blockquote>

    <blockquote class="layui-elem-quote">黑名单IP数量：[[${ipSize}]]
        <button type="button" class="layui-btn layui-btn-sm clear" t="serviceIpSize">清空</button>
    </blockquote>
    <blockquote class="layui-elem-quote">在读取的日志文件数：[[${readFileOnLineCount}]]
    </blockquote>
    <blockquote class="layui-elem-quote">在线构建文件占用空间：[[${cacheBuildFileSize}]]
    </blockquote>
</th:block>
<th:block th:if="${node}">
    <blockquote class="layui-elem-quote">文件缓存：
        <span th:nodeId="${node?.id}" fileSize> </span>
        <button type="button" class="layui-btn layui-btn-sm clear" th:nodeId="${node?.id}"
                t="fileSize">清空
        </button>
    </blockquote>
    <blockquote class="layui-elem-quote">进程名缓存：
        <span th:nodeId="${node?.id}" pidName></span>
        <button type="button" class="layui-btn layui-btn-sm clear" th:nodeId="${node?.id}"
                t="pidName">清空
        </button>
    </blockquote>
    <blockquote class="layui-elem-quote">进程端口缓存：
        <span th:nodeId="${node?.id}" pidPort></span>
        <button type="button" class="layui-btn layui-btn-sm clear" th:nodeId="${node?.id}"
                t="pidPort">清空
        </button>
    </blockquote>
    <blockquote class="layui-elem-quote">错误进程缓存：
        <span th:nodeId="${node?.id}" pidError></span>
        <button type="button" class="layui-btn layui-btn-sm clear" th:nodeId="${node?.id}"
                t="pidError">清空
        </button>
    </blockquote>

    <blockquote class="layui-elem-quote">在读取的日志文件数：
        <span th:nodeId="${node?.id}" readFileOnLineCount></span>
    </blockquote>
</th:block>
</body>
<script>
    function loadSuccess() {
        if ([[${node!=null?true:false}]]) {
            getCache("[[${node?.id}]]");
        }

        $(".clear").click(function () {
            var nodeId = $(this).attr("nodeId");
            var t = $(this).attr("t");
            layer.confirm('确定清除此缓存吗？', {
                title: '系统提示'
            }, function (index) {
                layer.close(index);
                loadingAjax({
                    url: './clearCache.json',
                    data: {
                        type: t,
                        nodeId: nodeId
                    },
                    success: function (data) {
                        layer.msg(data.msg);
                        if (200 === data.code) {
                            setTimeout(function () {
                                location.reload();
                            }, 2000)
                        }
                    }
                });
            });
        });
    }

    function getCache(nodeId) {
        loadingAjax({
            url: './node_cache.json',
            data: {
                nodeId: nodeId
            },
            success: function (data) {
                if (200 !== data.code) {
                    layer.msg(data.msg);
                    return;
                }
                for (var key in data.data) {
                    $("span[" + key.toLowerCase() + "][nodeId='" + nodeId + "']").text(data.data[key]);
                }
                $("button[nodeId='" + nodeId + "']").show();
            }
        });
    }
</script>
</html>
